<template>
  <div>
    <el-form label-width="180px" style="height:508px;overflow:auto">
      <el-row>
        <el-col :span="24" style="margin:5px 0">
          <el-button @click="previousPage" type="success" plain style="float:right;" icon="el-icon-arrow-left">
            返回</el-button>
        </el-col>
        <el-col :span="18">
          <el-form-item label="策略名称：">
            <el-input v-model.trim="name" size="mini" placeholder="请输入用户名" disabled clearable></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col v-for="(item,index) in RootDevList" :span="24" :key="index">
          <el-form-item :label="item.label">
            <el-radio-group v-model="item.Status" :disabled="item.disabled" v-if="item.Type!==2">
              <el-radio :label="3">禁用</el-radio>
              <el-radio :label="4">启用</el-radio>
            </el-radio-group>
            <el-radio-group v-model="item.Status" v-if="item.Type==2" :disabled="item.disabled">
              <el-radio :label="4" v-if="item.Type==2">启用</el-radio>
              <el-radio :label="3" v-if="item.Type==2">禁用</el-radio>
              <el-radio :label="2" v-if="item.Type==2">读写</el-radio>
              <el-radio :label="1" v-if="item.Type==2">只读</el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>

      </el-row>

    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button type="primary" @click="addTerminal" size="mini">确 定</el-button>
      <el-button @click="resetForm('ruleForm')" size="mini">重置</el-button>
    </span>
  </div>
</template>

<script>
export default {
  name: "mabDevice",
  data() {
    return {
      name: "",
      infoForm: [],
      RootDevList: [
        {
          Type: 2,
          label: "刻录",
          Status: 1,
        },
        {
          Type: 13,
          label: "打印机",
          Status: 3,
        },
        {
          Type: 16,
          label: "网卡",
          Status: 4,
        },
        {
          Type: 19,
          label: "图像设备",
          Status: 3,
        },
        {
          Type: 21,
          label: "智能卡读卡器",
          Status: 3,
        },
        {
          Type: 23,
          label: "SCSI和RAID控制器",
          Status: 3,
          disabled: true,
        },
        {
          Type: 28,
          label: "串口",
          Status: 3,
        },
        {
          Type: 29,
          label: "并口",
          Status: 3,
        },
        {
          Type: 7,
          label: "蓝牙设备",
          Status: 3,
          disabled: true,
        },
        {
          Type: 6,
          label: "红外设备",
          Status: 3,
          disabled: true,
        },
        {
          Type: 11,
          label: "调制解调器",
          Status: 3,
          disabled: true,
        },
        {
          Type: 35,
          label: "存储驱动器",
          Status: 3,
          disabled: true,
        },
        {
          Type: 36,
          label: "Windows CE同步设备",
          Status: 3,
          disabled: true,
        },
        {
          Type: 24,
          label: "软驱控制器",
          Status: 3,
          disabled: true,
        },
        {
          Type: 33,
          label: "光驱",
          Status: 4,
          disabled: true,
        },
        {
          Type: 37,
          label: "电池及UPS设备",
          Status: 4,
          disabled: true,
        },
        {
          Type: 38,
          label: "生物特征识别设备",
          Status: 4,
          disabled: true,
        },
        {
          Type: 39,
          label: "磁盘驱动器",
          Status: 3,
          disabled: true,
        },
        {
          Type: 40,
          label: "显示卡",
          Status: 4,
          disabled: true,
        },
        {
          Type: 41,
          label: "硬盘控制器",
          Status: 4,
          disabled: true,
        },
        {
          Type: 42,
          label: "人体学输入设备",
          Status: 4,
          disabled: true,
        },
        {
          Type: 43,
          label: "键盘",
          Status: 4,
          disabled: true,
        },
        {
          Type: 44,
          label: "显示器",
          Status: 4,
          disabled: true,
        },
        {
          Type: 45,
          label: "鼠标",
          Status: 4,
          disabled: true,
        },
        {
          Type: 46,
          label: "多媒体设备",
          Status: 4,
          disabled: true,
        },
        {
          Type: 47,
          label: "存储卷",
          Status: 4,
          disabled: true,
        },
        {
          Type: 48,
          label: "PCI/PCIE接口",
          Status: 4,
          disabled: true,
        },
        {
          Type: 49,
          label: "SATA/IDE接口",
          Status: 4,
          disabled: true,
        },
        {
          Type: 50,
          label: "PS/2接口",
          Status: 4,
          disabled: true,
        },
        {
          Type: 51,
          label: "00(保留分类)",
          Status: 3,
          disabled: true,
        },
        {
          Type: 52,
          label: "03(人体工学设备)",
          Status: 4,
          disabled: true,
        },
        {
          Type: 53,
          label: "05(物理设备)",
          Status: 3,
          disabled: true,
        },
        {
          Type: 54,
          label: "09(集线器)",
          Status: 4,
          disabled: true,
        },
        {
          Type: 55,
          label: "0D(内容安全)",
          Status: 3,
          disabled: true,
        },
        {
          Type: 56,
          label: "DC(诊断设备)",
          Status: 3,
          disabled: true,
        },
        {
          Type: 57,
          label: "E0(无线控制器)",
          Status: 3,
          disabled: true,
        },
        {
          Type: 58,
          label: "EF(其他设备)",
          Status: 3,
          disabled: true,
        },
        {
          Type: 59,
          label: "FE(应用程序)",
          Status: 3,
          disabled: true,
        },
        {
          Type: 60,
          label: "01(保留分类)",
          Status: 3,
          disabled: true,
        },
        {
          Type: 61,
          label: "02(保留分类)",
          Status: 3,
          disabled: true,
        },
        {
          Type: 62,
          label: "0A(保留分类)",
          Status: 3,
          disabled: true,
        },
        {
          Type: 63,
          label: "0E(保留分类)",
          Status: 3,
          disabled: true,
        },
        {
          Type: 64,
          label: "0F(保留分类)",
          Status: 3,
          disabled: true,
        },
        {
          Type: 65,
          label: "FF(保留分类)",
          Status: 3,
          disabled: true,
        },
      ],
      rowData: {
        // Root:{
        //   DevList:{
        //     Dev:{}
        //   }
        // }
      },

      paramForm: {},
    };
  },
  created() {
    this.getRootDevList();
  },
  methods: {
    //返回上一页
    previousPage() {
      this.$router.go(-1);
    },
    getRootDevList() {
      this.rowData = this.$route.params;
      this.name = this.$route.params.name;
      console.log(this.$route.params, 978);
      this.infoForm = this.$route.params.Root.DevList.Dev;
      this.RootDevList.forEach((item,index) => {
        this.infoForm.forEach((it) => {
          if (item.Type == it.Type) {
            item.Status = it.Status
          }
        });
      });
    },
    //确 定
    addTerminal() {
      this.$confirm("确认要提交吗？", "提示", {
        confirmButtonText: "确 定",
        cancelButtonText: "取 消",
        type: "warning",
      })
        .then(() => {
          this.paramForm.policy = {
            Root: {
              DevList: {
                Dev: this.RootDevList,
              },
            },
            creator: "secadm",
            enableTime: this.rowData.enableTime,
            name: this.name,
            state: this.rowData.state,
          };

          console.log(this.paramForm, "sss");
          this.$postForJson("/3in1/policy/devio", this.paramForm).then(
            (jsonData) => {
              this.$message({
                type: "success",
                message: "提交成功！",
              });
              this.$router.go(-1);
            }
          );
        })
        .catch((_) => {
          this.$message({
            type: "info",
            message: "已取消提交",
          });
        });
    },
    //重置
    resetForm() {
      this.$confirm("确认要重置吗？", "提示", {
        confirmButtonText: "确 定",
        cancelButtonText: "取 消",
        type: "warning",
      })
        .then(() => {
          this.getRootDevList();
          this.$message({
            type: "success",
            message: "重置成功！",
          });
        })
        .catch((_) => {
          this.$message({
            type: "info",
            message: "已取消重置",
          });
        });
    },
  },
};
</script>

<style scoped>
.el-form-item {
  margin-bottom: 5px !important;
}
</style>
